/**
 * 系统全局Modal数据存储
 */

//设置默认State
const getDefaultState = () => {
  return {
    authMode: 'page', // 授权模式:弹窗(modal)/独立页面(page); 默认值:page
    authType: 'mobileLogin', // 登录方式: accountLogin:密码登录 | mobileLogin:手机号登录注册 | forgotPwd:忘记密码 | changePwd:修改密码 | bindMobile:绑定手机号
    shareModal: false, // 分享弹框
    shareGuide: false, // H5端分享引导弹框
  }
}
//初始化State
const state = getDefaultState()

const mutations = {
  Set_AUTH_MODAL_MODE(state, type) {
    state.authMode = type
  },

  Set_AUTH_MODAL_TYPE(state, type) {
    state.authType = type
  },

  SET_SHARE_MODAL(state, boolean) {
    state.shareModal = boolean
  },

  SET_SHARE_GUIDE(state, boolean) {
    state.shareGuide = boolean
  },

  RESET_STATE(state) {
    Object.assign(state, getDefaultState())
  },
}

const actions = {
  ResetState({ commit }) {
    commit('RESET_STATE')
  },

  // 设置登录模式：弹窗(modal)/独立页面(page); 默认值:page
  SetAuthMode({ commit }, type = 'page') {
    commit('Set_AUTH_MODAL_MODE', type)
  },

  // 设置登录(账号密码||手机验证码)/找回密码/绑定手机号模式：弹窗弹出/隐藏; 默认值:mobileLogin
  SetAuthType({ commit }, type = 'mobileLogin') {
    commit('Set_AUTH_MODAL_TYPE', type)
  },

  // 设置分享弹框
  SetShareModal({ commit }, show = false) {
    commit('SET_SHARE_MODAL', show)
  },

  // 设置分享引导弹框
  SetShareGuide({ commit }, show = false) {
    commit('SET_SHARE_GUIDE', show)
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
